package org.dromara.learning_lhz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.learning_lhz.entity.AsStudyEntity;
import org.dromara.learning_lhz.mapper.StudyMapper;
import org.dromara.learning_lhz.service.StudyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Service
public class StudyServiceImpl extends ServiceImpl<StudyMapper, AsStudyEntity> implements StudyService {

    @Autowired
    private StudyMapper studyMapper;
    // 查询试卷
    @Override
    public List<AsStudyEntity> selStudy(AsStudyEntity asStudyEntity) {

        LambdaQueryWrapper<AsStudyEntity> queryWrapper = new LambdaQueryWrapper<>();

        if (Objects.nonNull(asStudyEntity.getSubject())) {
            queryWrapper.eq(AsStudyEntity::getSubject, asStudyEntity.getSubject());
        }

        if (Objects.nonNull(asStudyEntity.getSemester())) {
            queryWrapper.eq(AsStudyEntity::getSemester, asStudyEntity.getSemester());
        }

        if (Objects.nonNull(asStudyEntity.getGrade())) {
            queryWrapper.eq(AsStudyEntity::getGrade, asStudyEntity.getGrade());
        }

        if (Objects.nonNull(asStudyEntity.getLearningStage())) {
            queryWrapper.eq(AsStudyEntity::getLearningStage, asStudyEntity.getLearningStage());
        }

        return studyMapper.selectList(queryWrapper);


    }

    // 添加试卷
    @Override
    public void addStudy(AsStudyEntity asStudyEntity) {
        LoginHelper.getLoginUser().getUsername();
        asStudyEntity.setCreateBy(LoginHelper.getUserId());
        this.save(asStudyEntity);
    }
}
